import os

import pymysql

from config import db
from tool.get_log import GetLogger

log = GetLogger.get_log()


def read_sql(phone_number):
    # """读取navicat转储文件，恢复表"""
    # log.info(f'读取navicat转储文件{filename}，恢复表')
    # path = BASE_PATH + os.sep + 'data' + os.sep + filename
    # with open(path, 'r', encoding='utf-8') as f:
    #     sql_list = []
    #     for line in f.readlines():
    #         if line.startswith('SET'):
    #             sql_list.append(line.replace('\n', ''))
    #         elif line.startswith('DROP'):
    #             sql_list.append(line.replace('DROP', 'TRUNCATE').replace(' IF EXISTS', '').replace('\n', ''))
    #         elif line.startswith('INSERT'):
    #             sql_list.append(line.replace('\n', ''))
    #         else:
    #             pass

    conn = pymysql.connect(host=db['php']['host'],
                           user=db['php']['user'],
                           passwd=db['php']['password'],
                           database=db['php']['database'],
                           port=db['php']['port'],
                           charset='utf8'
                           )
    c = conn.cursor()
    # for sql in sql_list:
    #     c.execute(sql)
    sql = f"SELECT zz.mobile,zclr.adddate,zcl.title FROM zd_customer_label_relation AS zclr" \
          f" LEFT JOIN zd_customer_label AS zcl ON zcl.id = zclr.lid " \
          f"LEFT JOIN zd_customer AS zc ON zc.cid = zclr.cid " \
          f"LEFT JOIN zd_zixun AS zz ON zz.id = zc.zid WHERE zz.mobile = '{phone_number}'"

    result = c.execute(sql)
    print(f"一共查到{result}条数据")
    print(c.fetchall())
    conn.commit()
    c.close()
    conn.close()



if __name__ == '__main__':
    read_sql('16300010025')
